package com.lt.basic.project.pojo.entity.mino.user;

import com.lt.basic.project.common.uid.Id;
import com.lt.basic.project.common.util.StringUtils;
import com.lt.basic.project.pojo.validate.mino.user.UserVisitsCreateValidate;
import com.lt.basic.project.pojo.validate.mino.user.UserVisitsUpdateValidate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * la_user_visits数据实体
 * @author ：LT
 * @Created in : 2023-08-31
 */

@Data
@ApiModel(value = "UserVisits对象", description = "la_user_visits表")
public class UserVisits implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    private Long id;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 请求类型: GET/POST/PUT
     */
    private String type;

    /**
     * 请求IP
     */
    private String ip;

    /**
     * 请求接口
     */
    private String url;

    /**
     * 请求方法
     */
    private String method;

    /**
     * 请求参数
     */
    private String args;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 是否新增
     */
    private Boolean isNew;

    /**
    * 添加数据
    */
    public void create(UserVisitsCreateValidate createValidate) {
        setId(Id.getId());
        setUserId(createValidate.getUserId());
        setType(createValidate.getType());
        setIp(createValidate.getIp());
        setUrl(createValidate.getUrl());
        setMethod(createValidate.getMethod());
        setArgs(createValidate.getArgs());
        setCreateTime(new Date());
    }

    /**
    * 编辑数据
    */
    public void modify(UserVisitsUpdateValidate updateValidate) {
        if (StringUtils.isNotObj(updateValidate.getUserId())) {
            setUserId(updateValidate.getUserId());
        }
        if (StringUtils.isNotObj(updateValidate.getType())) {
            setType(updateValidate.getType());
        }
        if (StringUtils.isNotObj(updateValidate.getIp())) {
            setIp(updateValidate.getIp());
        }
        if (StringUtils.isNotObj(updateValidate.getUrl())) {
            setUrl(updateValidate.getUrl());
        }
        if (StringUtils.isNotObj(updateValidate.getMethod())) {
            setMethod(updateValidate.getMethod());
        }
        if (StringUtils.isNotObj(updateValidate.getArgs())) {
            setArgs(updateValidate.getArgs());
        }
    }

}